package com.hedd.shop.controller;

import com.hedd.shop.pojo.entity.Address;
import com.hedd.shop.pojo.qo.AddressAddQO;
import com.hedd.shop.pojo.qo.AddressStatusQO;
import com.hedd.shop.pojo.qo.AddressUpdateQO;
import com.hedd.shop.pojo.vo.RespResult;
import com.hedd.shop.service.AddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ludi
 * @date:2020/9/1 16:12
 * @description:地址业务控制层
 */
@Controller
@RestController
@RequestMapping("/address")
@Api(tags = "地址业务接口")
public class AddressController extends BaseController {
    @Autowired
    private AddressService addressService;

    @PostMapping("/addAddress")
    @ApiOperation("新增地址")
    public RespResult addAddress(@RequestBody AddressAddQO addressAddQO){
        Integer value = addressService.addAddress(addressAddQO);
        return returnRespWithSuccess(value);
    }

    @GetMapping("/selectAddressByUserId")
    @ApiOperation("查询用户所有地址")
    public RespResult selectAddressByUserId(Integer userId){
        List<Address> list = addressService.selectAddressByUserId(userId);
        return returnRespWithSuccess(list);
    }

    @GetMapping("/deleteAddress")
    @ApiOperation("删除地址")
    public RespResult deleteAddress(Integer addressId){
        Integer value = addressService.deleteAddress(addressId);
        return returnRespWithSuccess(value);
    }

    @PostMapping("/updateAddress")
    @ApiOperation("修改地址")
    public RespResult updateAddress(@RequestBody AddressUpdateQO addressUpdateQO){
        Integer value = addressService.updateAddress(addressUpdateQO);
        return returnRespWithSuccess(value);
    }

    @PostMapping("/updateStatus")
    @ApiOperation("修改地址默认状态")
    public RespResult updateStatus(@RequestBody AddressStatusQO addressStatusQO){
        Integer value = addressService.updateStatus(addressStatusQO);
        return returnRespWithSuccess(value);
    }

}
